

package pos.control;

import java.sql.ResultSet;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import pos.Pos;
import pos.entity.Item;
import pos.storage.db.sql.SQL;
/**
 * This class is a control object that get the category from the database.
 * @author wei zhang
 */
public class RetriveCategoryControl {
    /**
     * This method query from the database and returns an array list of category
     * to the caller.
     * @return
     */
    public ArrayList retriveCategory (){
        ArrayList category = new ArrayList();
        String retriveCate = "";
        try{
            ResultSet rs;
            Statement stmt;
            retriveCate = "select CategoryId,CategoryName from category";
            stmt = Pos.adminConn.createStatement();
            rs = stmt.executeQuery(retriveCate);
            while(rs.next()){
                retriveCate = rs.getString("CategoryName");
                retriveCate = retriveCate + " ID:"+rs.getString("CategoryId");
                category.add(retriveCate);
            }
            for(int i = 0 ; i < category.size(); i++){
                System.out.println(category.get(i));
            }
            return category;
        }
        catch(SQLException e){
            e.printStackTrace();
        }
        return category;

    }


}
